<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Site extends Model
{
    use SoftDeletes;

    protected $table = 'sites';

    protected $fillable = ['user_id','capacity','status','zone','name', 'province','city','town','address', 'img', 'position', 'description','equipment_num'];

    public function groups()
    {
        return $this->hasMany('App\Model\Group');
    }


    public static function getSitesByUserId($user_id)
    {
        $sites = Site::where('user_id', $user_id)->get();
        return $sites;
    }

    public static function deleteUserSite($user_id, $id)
    {
        $site = Site::where('user_id', $user_id)->where('id', $id)->first();
        if ($site) {
            $site->delete();
            return true;
        } else {
            return false;
        }
    }

    public static function getSitesTotalByUserId($user_id)
    {
        $total = Site::where('user_id', $user_id)->count();
        return $total;
    }

}
